﻿/********************************************************************************************************************
* Author:	Aris Michail																							*
* Email:	std03055@di.uoa.gr																						*
* Purpose:	This script is used in order to create the stored procedure "usp_category_getentitieswithvalues" that	*
*			returns all entities with their attributes and values.													*
********************************************************************************************************************/

CREATE PROCEDURE [dbo].[usp_getEntities]
	@categoryid bigint,
	@entityname	nvarchar(50)
AS
	SELECT entities.name as ent_name,attributes.name as attr_name,[entity-attribute].value, Entities.ID, Attributes.ID
	FROM entities,attributes,[entity-attribute]
	WHERE entities.category = @categoryid and
		entities.name LIKE @entityname and
		entities.category = attributes.category and
		[entity-attribute].entity = entities.id and
		[entity-attribute].attribute = attributes.id
	ORDER BY ent_name
RETURN 0